﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace CuteRibs.MVVMLib
{
	public abstract class PageViewModelBase : ViewModelBase
	{
		protected Frame Frame { get { return Application.Current.RootVisual as Frame; } }

		private string pageTitle;
		private bool showProgressBar;

		public string PageTitle
		{
			get { return this.pageTitle; }
			set
			{
				if (this.pageTitle != value)
				{
					this.pageTitle = value;
					this.NotifyPropertyChanged("PageTitle");
				}
			}
		}

		public bool ShowProgressBar
		{
			get { return this.showProgressBar; }
			set
			{
				if (this.showProgressBar != value && !DesignerProperties.IsInDesignTool)
				{
					this.showProgressBar = value;
					this.NotifyPropertyChanged("ShowProgressBar");
				}
			}
		}

		public PageViewModelBase()
		{
			this.ShowProgressBar = false;
		}

		protected void BeginInvoke(Action action)
		{
			Deployment.Current.Dispatcher.BeginInvoke(action);
		}

		public virtual void OnNavigatedFrom(ViewBase sender, NavigationEventArgs eventArgs, NavigationContext context) { }

		public virtual void OnNavigatedTo(ViewBase sender, NavigationEventArgs eventArgs, NavigationContext context) { }
	}
}
